/*
 * Copyright (C), 2014-2015, 杭州小卡科技有限公司
 * FileName: InsResult.java
 * Author:   muxing
 * Date:    2015/10/19 18:15
 * Description:
 */
package com.xiaoka.ins.corp.common.dto.base;

import com.xiaoka.freework.utils.json.Jackson;

/**
 * Ins返回统一的结果对象
 *
 * @author muxing
 * @date 2015/10/19
 */
public class InsResult<T> {
	/**
	 * 是否成功
	 */
	private boolean success = true;
	/**
	 * 自定义的状态码
	 */
	private int code = 0;
	/**
	 * 返回的消息内容，一般是失败情况的原因说明
	 */
	private String message;
	/**
	 * 返回的数据对象
	 */
	private T data;

	public InsResult() {
	}

	public InsResult(T data) {
		this.data = data;
	}

	public InsResult(int code, String message) {
		this(code, message, null);
	}

	public InsResult(int code, String message, T cause) {
		this.success = false;
		this.message = message;
		this.code = code;
		this.data = cause;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public String toJson() {
		return Jackson.mobile().writeValueAsString(this);
	}
}